import defaultSettings from '@/settings'
import useSettingsStore from '@/store/modules/settings'
import { getConfigKey } from '@/api/system/config'

/**
 * 动态修改标题
 */
export function useDynamicTitle() {
  const settingsStore = useSettingsStore()
  if (settingsStore.dynamicTitle) {
    document.title = settingsStore.title + ' - ' + defaultSettings.title
  } else {
    document.title = title
  }
}

let title = defaultSettings.title

function getDefaultTitle() {
  getConfigKey('defaultTitle').then((res) => {
    title = res.msg
  })
}

getDefaultTitle()
